 package sza.oracle.apps.ap.oie.traveExp.webui;
 
 import com.sun.java.util.collections.HashMap;
 import java.io.PrintStream;
 import java.io.Serializable;
 import java.sql.CallableStatement;
 import java.sql.SQLException;
 import oracle.apps.ap.oie.entry.webui.EntryFlowPageCO;
 import oracle.apps.ap.oie.framework.webui.OIEPageCO;
 import oracle.apps.ap.oie.webui.NavigationUtility;
 import oracle.apps.fnd.common.MessageToken;
 import oracle.apps.fnd.common.VersionInfo;
 import oracle.apps.fnd.framework.OAApplicationModule;
 import oracle.apps.fnd.framework.OAException;
 import oracle.apps.fnd.framework.OAViewObject;
 import oracle.apps.fnd.framework.server.OADBTransaction;
 import oracle.apps.fnd.framework.webui.OAControllerImpl;
 import oracle.apps.fnd.framework.webui.OAPageContext;
 import oracle.apps.fnd.framework.webui.OAPartialPageRenderUtils;
 import oracle.apps.fnd.framework.webui.beans.OAWebBean;
 import oracle.apps.fnd.framework.webui.beans.layout.OAPageLayoutBean;
 import oracle.apps.fnd.framework.webui.beans.nav.OATrainBean;
 import oracle.cabo.ui.collection.UINodeList;
 import oracle.jbo.Row;
 import sza.oracle.apps.ap.oie.server.ExpenseTypeHierarchyVOImpl;
 import sza.oracle.apps.ap.oie.utility.SzaOIEUtil;
 
 public class ExpenseTypeTreeCO extends OAControllerImpl
 {
   public static final String RCS_ID = "$Header$";
   public static final boolean RCS_ID_RECORDED = VersionInfo.recordClassVersion("$Header$", "%packagename%");
   
   String expenseDetailId = "";
   String lineNumber = "";
 
   public void processRequest(OAPageContext pageContext, OAWebBean webBean)
   {
     String LogMessage = "";
     String LogFunction = "";
    
       super.processRequest(pageContext, webBean);
     expenseDetailId = pageContext.getParameter("expenseDetailIdm");
     lineNumber = pageContext.getParameter("lineNumber");
//     pageContext.putTransactionValue("expenseDetailId", expenseDetailId);
//     pageContext.putTransactionValue("lineNumber", lineNumber);
     System.out.println("ExpenseTypeTreeCO.processRequest(): expenseDetailId:"+expenseDetailId);
     System.out.println("ExpenseTypeTreeCO.processRequest(): lineNumber:"+lineNumber);
 
     String CurrentPage = NavigationUtility.getCurrentPage(pageContext);
     
     SzaOIEUtil.cmlinLog(pageContext, LogFunction, LogMessage);
     if (CurrentPage.equals("ExpenseTypeTreePG"))
     {
       CurrentPage = "CashAndOtherLinesPG";
     }
     if (!pageContext.isFormSubmission())
     {
       OAWebBean treeRN = webBean.findIndexedChildRecursive("TreeRN");
       if (treeRN != null)
       {
         treeRN.setRendered(true);
 
         initPage(pageContext, webBean);
       }
 
     }
      
   }
 
   public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
   {
     String LogMessage = "";
     String LogFunction = "";
    
     super.processFormRequest(pageContext, webBean);
 
     processRequestPageButtons(pageContext, webBean);
 
     OAPartialPageRenderUtils.addPartialTargets(pageContext, "TreeRN");
 
     processTreeNodePost(pageContext, webBean);
   }
 
   private void processTreeNodePost(OAPageContext pageContext, OAWebBean webBean)
   {
     String LogMessage = "";
     String LogFunction = "";
    
     String IsExpenseRecognitionReport = (String)pageContext.getTransactionValue("IsExpenseRecognitionReport");
 
     OAApplicationModule am = pageContext.getApplicationModule(webBean);
 
     if ("LinkExpenseTypeTree".equals(pageContext.getParameter("event")))
     {
       
    
       String SelectedTreeNodeValue = null;
       SelectedTreeNodeValue = pageContext.getParameter("SelectedTreeNodeValue");
 
       String ExpTypeAttribute1 = null;
       ExpTypeAttribute1 = pageContext.getParameter("ExpTypeAttribute1");
      
       String ExpTypeAttribute2 = null;
       ExpTypeAttribute2 = pageContext.getParameter("ExpTypeAttribute2");
      
       String ExpTypeAttribute3 = null;
       ExpTypeAttribute3 = pageContext.getParameter("ExpTypeAttribute3");
       
       String ExpTypeAttribute4 = null;
       ExpTypeAttribute4 = pageContext.getParameter("ExpTypeAttribute4");
      
       String ExpTypeAttribute5 = null;
       ExpTypeAttribute5 = pageContext.getParameter("ExpTypeAttribute5");
       
       String ExpTypeAttribute6 = null;
       ExpTypeAttribute6 = pageContext.getParameter("ExpTypeAttribute6");
       
       String ExpTypeAttribute7 = null;
       ExpTypeAttribute7 = pageContext.getParameter("ExpTypeAttribute7");
       
       String ExpTypeAttribute8 = null;
       ExpTypeAttribute8 = pageContext.getParameter("ExpTypeAttribute8");
       
       String ExpTypeAttribute9 = null;
       ExpTypeAttribute9 = pageContext.getParameter("ExpTypeAttribute9");
       
       String ExpTypeAttribute10 = null;
       ExpTypeAttribute10 = pageContext.getParameter("ExpTypeAttribute10");
       
       String ExpTypeAttribute11 = null;
       ExpTypeAttribute11 = pageContext.getParameter("ExpTypeAttribute11");
       
       String ExpTypeAttribute12 = null;
       ExpTypeAttribute12 = pageContext.getParameter("ExpTypeAttribute12");
       
       String ExpTypeAttribute13 = null;
       ExpTypeAttribute13 = pageContext.getParameter("ExpTypeAttribute13");
       
       String ExpTypeAttribute14 = null;
       ExpTypeAttribute14 = pageContext.getParameter("ExpTypeAttribute14");
       
       String ExpTypeAttribute15 = null;
       ExpTypeAttribute15 = pageContext.getParameter("ExpTypeAttribute15");
       
       String ExpTypeSegment1 = null;
       ExpTypeSegment1 = pageContext.getParameter("ExpTypeSegment1");
      
       String ExpTypeSegment2 = null;
       ExpTypeSegment2 = pageContext.getParameter("ExpTypeSegment2");
      
       String ExpTypeSegment3 = null;
       ExpTypeSegment3 = pageContext.getParameter("ExpTypeSegment3");
      
       String ExpTypeSegment4 = null;
       ExpTypeSegment4 = pageContext.getParameter("ExpTypeSegment4");
       
       String ExpTypeSegment5 = null;
       ExpTypeSegment5 = pageContext.getParameter("ExpTypeSegment5");
       
       String ExpTypeSegment6 = null;
       ExpTypeSegment6 = pageContext.getParameter("ExpTypeSegment6");
       
       String ExpTypeSegment7 = null;
       ExpTypeSegment7 = pageContext.getParameter("ExpTypeSegment7");
       
       String ExpTypeSegment8 = null;
       ExpTypeSegment8 = pageContext.getParameter("ExpTypeSegment8");
      
       String ExpTypeSegment9 = null;
       ExpTypeSegment9 = pageContext.getParameter("ExpTypeSegment9");
      
       String ExpTypeSegment10 = null;
       ExpTypeSegment10 = pageContext.getParameter("ExpTypeSegment10");
       
       String ExpTypeSegment11 = null;
       ExpTypeSegment11 = pageContext.getParameter("ExpTypeSegment11");
      
       String ExpTypeSegment12 = null;
       ExpTypeSegment12 = pageContext.getParameter("ExpTypeSegment12");
      
       String ExpTypeSegment13 = null;
       ExpTypeSegment13 = pageContext.getParameter("ExpTypeSegment13");
       
       String ExpTypeSegment14 = null;
       ExpTypeSegment14 = pageContext.getParameter("ExpTypeSegment14");
       
       String ExpTypeSegment15 = null;
       ExpTypeSegment15 = pageContext.getParameter("ExpTypeSegment15");
       
       String TempSelectedTreeNodeValue = "";
       TempSelectedTreeNodeValue = TempSelectedTreeNodeValue + ExpTypeSegment1 + ".";
       TempSelectedTreeNodeValue = TempSelectedTreeNodeValue + ExpTypeSegment2 + ".";
       TempSelectedTreeNodeValue = TempSelectedTreeNodeValue + ExpTypeSegment3 + ".";
       TempSelectedTreeNodeValue = TempSelectedTreeNodeValue + "XXXXXXX.";
       TempSelectedTreeNodeValue = TempSelectedTreeNodeValue + ExpTypeSegment5;
       if ((ExpTypeSegment6 != null) && (ExpTypeSegment6 != ""))
       {
         TempSelectedTreeNodeValue = TempSelectedTreeNodeValue + "." + ExpTypeSegment6;
       }
 
      
       if ((ExpTypeAttribute15 != null) && (!"".equalsIgnoreCase(ExpTypeAttribute15)))
       {
         String FlexConcatenated = "";
         String $$FWK_MultiOrgCurrentOrgId = "";
         String TemplateId = "";
         String EmployeeId ="";
         String CompanyCode ="";
         String BudgetCostCenterCode = "";
         OAApplicationModule rootAM = pageContext.getRootApplicationModule();
         OAViewObject HeaderVo = (OAViewObject)rootAM.findViewObject("ExpenseReportHeadersVO");
 
         if (HeaderVo != null)
         {
           FlexConcatenated = (String)HeaderVo.getCurrentRow().getAttribute("FlexConcatenated");
           BudgetCostCenterCode = (String)HeaderVo.getCurrentRow().getAttribute("Attribute12");
           $$FWK_MultiOrgCurrentOrgId = HeaderVo.getCurrentRow().getAttribute("OrgId")+"";
           TemplateId = HeaderVo.getCurrentRow().getAttribute("ExpenseReportId")+"";
           EmployeeId = HeaderVo.getCurrentRow().getAttribute("EmployeeId")+"";
           CompanyCode = SzaOIEUtil.getEmployeeCompanyCode(pageContext, webBean, EmployeeId);
         }
 
        
         String ExpItem01 = ExpTypeSegment5;
         if (ExpItem01 == null)
         {
           ExpItem01 = "0";
         }
         String ExpItem02 = ExpTypeSegment6;
         if (ExpItem02 == null)
         {
           ExpItem02 = "0";
         }
 
         if ((BudgetCostCenterCode == null) || (BudgetCostCenterCode == ""))
         {
           BudgetCostCenterCode = FlexConcatenated;
         }
         
           String GlAccount = SzaOIEUtil.getGlAccount(pageContext, webBean, $$FWK_MultiOrgCurrentOrgId, TemplateId, CompanyCode, FlexConcatenated, ExpItem01, ExpItem02);
 
          
//          String expenseDetailId =  (String)pageContext.getTransactionValue("expenseDetailId");
//          String lineNumber = (String)pageContext.getTransactionValue("lineNumber");
 
         HashMap hashmap = new HashMap();
         hashmap.put("ExpTypeAttribute1",ExpTypeAttribute1);
         hashmap.put("ExpTypeAttribute2",ExpTypeAttribute2);
         hashmap.put("ExpenseCategory",ExpTypeAttribute2);
         hashmap.put("TempSelectedTreeNodeValue",TempSelectedTreeNodeValue);
         hashmap.put("SelectedTreeNodeValue",SelectedTreeNodeValue);
         hashmap.put("ExpTypeAttribute3",ExpTypeAttribute3);
         hashmap.put("ExpTypeAttribute4",ExpTypeAttribute4);
         hashmap.put("ExpTypeAttribute5",ExpTypeAttribute5);
         hashmap.put("ExpTypeAttribute6",ExpTypeAttribute6);
         hashmap.put("ExpTypeAttribute7",ExpTypeAttribute7);
         hashmap.put("ExpTypeAttribute12",ExpTypeAttribute12);
         hashmap.put("ExpTypeAttribute13",ExpTypeAttribute13);
         hashmap.put("ExpTypeAttribute14",ExpTypeAttribute14);
         hashmap.put("GlAccount",GlAccount);
         hashmap.put("lineNumber",lineNumber);
         hashmap.put("expenseDetailIdt",expenseDetailId);
//         OAViewObject LineVo = (OAViewObject)am.findViewObject("SzaOieExpenseDetailTVO1");
// 
//         if (LineVo != null)
//         {
//           System.out.println("lineVO is not null");
//           LineVo.first();
//           System.out.println("lineVo.length"+LineVo.getRowCount());
//           Row[] rows = LineVo.getFilteredRows("ExpenseDetailId",expenseDetailId);
//           System.out.println("rows.length:"+rows.length);
//           Row row = null;
//           for(int i=0;i<rows.length;i++){
//               row = rows[i];
//               row.setAttribute("Attribute6", ExpTypeAttribute1);
//               
//               row.setAttribute("ExpenseDesc", ExpTypeAttribute2);
//               
//               row.setAttribute("ExpenseCategory", ExpTypeAttribute2);
//               
//               row.setAttribute("Attribute10", TempSelectedTreeNodeValue);  
//               
//               row.setAttribute("Attribute1", SelectedTreeNodeValue);
//               
//               row.setAttribute("Attribute2", ExpTypeAttribute12);
//               
//               row.setAttribute("Attribute3", ExpTypeAttribute13);
//               
//               row.setAttribute("Attribute4", ExpTypeAttribute14);
//               
//               row.setAttribute("Attribute5", GlAccount);
//           }
//          am.getTransaction().commit();
// 
//        }
           StringBuffer localStringBuffer = new StringBuffer("");
           localStringBuffer.append("OA.jsp?page=");
           localStringBuffer.append("/sza/oracle/apps/ap/oie/traveExp/webui/TravelDetailPG");
           pageContext.forwardImmediately(localStringBuffer.toString(), 
                                          "OIEENTRYFLOW", (byte)0, null, 
                                          hashmap, true, "N");
       }
 
     }
 
    }
 
   private void initPage(OAPageContext pageContext, OAWebBean webBean)
   {
     String LogMessage = "";
     String LogFunction = "";
     
     OAApplicationModule am = pageContext.getApplicationModule(webBean);
     OADBTransaction oadbtransaction = am.getOADBTransaction();
     OAApplicationModule rootAm = pageContext.getRootApplicationModule();
     OAViewObject HeaderVo = (OAViewObject)rootAm.findViewObject("ExpenseReportHeadersVO");
     String IsExpenseRecognitionReport = (String)pageContext.getTransactionValue("IsExpenseRecognitionReport");
     
     String $$FWK_MultiOrgCurrentOrgId = "";
     String TemplateId = "";
     String EmployeeId = "";
     String CompanyCode = "";
     String DefaultCostCenter = "";
     String FlexConcatenated = "";
     String BudgetCostCenterCode = "";
     if (HeaderVo != null)
     {
      
       FlexConcatenated = (String)HeaderVo.getCurrentRow().getAttribute("FlexConcatenated");
       BudgetCostCenterCode = (String)HeaderVo.getCurrentRow().getAttribute("Attribute12");
       $$FWK_MultiOrgCurrentOrgId = HeaderVo.getCurrentRow().getAttribute("OrgId")+"";
         
         
       TemplateId = HeaderVo.getCurrentRow().getAttribute("ExpenseReportId")+"";
         
         
       EmployeeId = HeaderVo.getCurrentRow().getAttribute("EmployeeId")+"";
         
         
       CompanyCode = SzaOIEUtil.getEmployeeCompanyCode(pageContext, webBean, EmployeeId);
         
         
       DefaultCostCenter = (String)HeaderVo.getCurrentRow().getAttribute("FlexConcatenated");
      
     }
 
    
     if ((BudgetCostCenterCode != null) && (BudgetCostCenterCode != ""))
     {
       FlexConcatenated = BudgetCostCenterCode;
     }
 
     if ("Y".equalsIgnoreCase(IsExpenseRecognitionReport))
     {
       FlexConcatenated = "";
     }
     super.processRequest(pageContext, webBean);
    
     ExpenseTypeHierarchyVOImpl vo = (ExpenseTypeHierarchyVOImpl)am.findViewObject("ExpenseTypeHierarchyVO1");
     if (vo == null)
     {
       vo = (ExpenseTypeHierarchyVOImpl)am.createViewObject("ExpenseTypeHierarchyVO1", "sza.oracle.apps.ap.oie.server.ExpenseTypeHierarchyVO");
      
     }
 
     if (vo != null)
     {
       vo.clearCache();
       vo.refreshWhereClauseParams();
 
       String strSql = "{call ";
       strSql = strSql + " sza_oie_exp_type_tree_pkg.SET_SEGMENT1(:1); ";
       strSql = strSql + " sza_oie_exp_type_tree_pkg.SET_SEGMENT2(:2); ";
       strSql = strSql + " sza_oie_exp_type_tree_pkg.SET_SEGMENT3(:3); ";
       strSql = strSql + " sza_oie_exp_type_tree_pkg.SET_SEGMENT4(:4); ";
       strSql = strSql + " sza_oie_exp_type_tree_pkg.SET_SEGMENT5(:5); ";
       strSql = strSql + " sza_oie_exp_type_tree_pkg.SET_SEGMENT6(:6);  ";
       strSql = strSql + " sza_oie_exp_type_tree_pkg.SET_SEGMENT7(:7); ";
       strSql = strSql + " sza_oie_exp_type_tree_pkg.SET_SEGMENT8(:8); ";
       strSql = strSql + " sza_oie_exp_type_tree_pkg.SET_SEGMENT9(:9); ";
       strSql = strSql + " sza_oie_exp_type_tree_pkg.SET_SEGMENT10(:10); ";
       strSql = strSql + " sza_oie_exp_type_tree_pkg.SET_SEGMENT11(:11); ";
       strSql = strSql + " sza_oie_exp_type_tree_pkg.SET_SEGMENT12(:12);  ";
       strSql = strSql + " sza_oie_exp_type_tree_pkg.SET_SEGMENT13(:13); ";
       strSql = strSql + " sza_oie_exp_type_tree_pkg.SET_SEGMENT14(:14); ";
       strSql = strSql + " sza_oie_exp_type_tree_pkg.SET_SEGMENT15(:15)  ";
 
       strSql = strSql + " } ";
       CallableStatement callablestatement = oadbtransaction.createCallableStatement(strSql, 1);
 
      
       try
       {
         callablestatement.setString(1, $$FWK_MultiOrgCurrentOrgId);
 
         callablestatement.setString(2, TemplateId);
 
         callablestatement.setString(3, CompanyCode);
 
         callablestatement.setString(4, FlexConcatenated);
 
         callablestatement.setString(5, "");
 
         callablestatement.setString(6, "");
 
         callablestatement.setString(7, "");
 
         callablestatement.setString(8, "");
 
         callablestatement.setString(9, "");
 
         callablestatement.setString(10, "");
 
         callablestatement.setString(11, "");
 
         callablestatement.setString(12, "");
 
         callablestatement.setString(13, "");
 
         callablestatement.setString(14, "");
 
         callablestatement.setString(15, "");
 
         callablestatement.execute();
       }
       catch (SQLException sqlexception)
       {
         oadbtransaction.rollback();
         throw OAException.wrapperException(sqlexception);
       }
       finally
       {
         try
         {
           callablestatement.close();
         }
         catch (Exception localException1)
         {
           throw OAException.wrapperException(localException1);
         }
       }
       oadbtransaction.commit();
 
       String WhereClause = " 1 = 1 ";
       WhereClause = WhereClause + " AND TRIM(tree_node_code_p) = '0' ";
 
       vo.setWhereClause(WhereClause);
       vo.setWhereClauseParams(null);
       vo.executeQuery();
     }
   }
 
   private void processRequestPageButtons(OAPageContext pageContext, OAWebBean webBean)
   {
     String LogMessage = "";
     String LogFunction = "";
     
 
     if ("ReturnButton".equals(pageContext.getParameter("event")))
     {         HashMap hashmap = new HashMap();
         hashmap.put("exeInit","Y");
         StringBuffer localStringBuffer = new StringBuffer("");
         localStringBuffer.append("OA.jsp?page=");
         localStringBuffer.append("/sza/oracle/apps/ap/oie/traveExp/webui/TravelDetailPG");
         pageContext.forwardImmediately(localStringBuffer.toString(), 
                                        "OIEENTRYFLOW", (byte)0, null, 
                                        hashmap, true, "N");
     }
    }
 }



